package List;

import java.util.ArrayList;

public class ListDemo {
    public static void main(String[] args) {
        /*创建List集合对象*/
        ArrayList<Student> list = new ArrayList<>();
        /*创建学生对象*/
        Student s1 = new Student("林青霞", 30);
        Student s2 = new Student("张曼玉", 35);
        Student s3 = new Student("王祖贤",33);
        /*把学生添加到集合*/
        list.add(s1);
        list.add(s2);
        list.add(s3);
        /*迭代器方式进行遍历*/
        for (Student student : list) {
            System.out.println(student.getName()+","+student.getAge());
        }
        System.out.println("-----------");
        /*for循环方式*/
        for (int i = 0; i < list.size(); i++) {
            Student s = list.get(i);
            System.out.println(s.getName()+","+s.getAge());
        }
    }
}
/*
* Student类
* */
class Student{
    private String name;
    private int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public Student() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}